package com.platform.common.mybatis.dialect;

import com.platform.common.annotation.logger.EnableLogger;
import com.platform.common.util.SqlUtil;
import org.apache.log4j.Logger;

public class MySQLDialect implements Dialect {

    private static Logger logger = Logger.getLogger(MySQLDialect.class);

    /**
     * 将SQL语句包装成分页查询SQL
     *
     * @param querySql SQL语句
     * @param offset   开始行
     * @param limit    查询条数
     * @return SQL语句
     */
    @Override
    public String getLimitString(String querySql, int offset, int limit) {
        StringBuffer buffer = new StringBuffer(" limit ");
        if (offset > -1) {
            buffer.append(offset).append(",").append(limit);
        } else {
            buffer.append(limit);
        }
        String sql = new StringBuffer(querySql.length() + 20).append(querySql).append(buffer).toString();

        logger.info("getLimitString to sql :" + sql);

        return sql;
    }

}
